public class Solution {
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        k=k%len;
        reverse(nums, 0, len - k - 1);
        reverse(nums, len - k, len - 1);
        reverse(nums, 0, len - 1);
    }

    public void reverse(int[] nums, int start, int end) {
        int t;
        for(int i = start; i <= (start + end) / 2; i++) {
            t = nums[i];
            nums[i] = nums[end + start - i];
            nums[end + start - i] = t;
        }
    }
}